/**
 * 
 */
package kr.pe.osdev.helper;

import java.lang.reflect.Field;

import kr.pe.osdev.annotation.PrintToString;

/**
 * @author painworld
 * 
 */
public class ToStringHelper {
	public static String toString(Object obj) {
		StringBuffer buffer = new StringBuffer();
		
		try {
			Class<? extends Object> clazz = obj.getClass();
			buffer.append(clazz.getName()).append(" { ");
			
			for (Field field : clazz.getDeclaredFields()) {
				PrintToString pts = field.getAnnotation(PrintToString.class);
				if (pts != null) {
					Object value = BeansHelper.getGetterMethod(clazz, field).invoke(obj);
					buffer.append(field.getName()).append("=").append(value).append(",");
				}
			}
			
			buffer.append(" }");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return buffer.toString();
	}
}
